<?php
class Classes_MySQL {
	var $result='';
	var $test='';
	var $row='';
	var $insert_id = '';
	
	function __construct(){
		#echo HOST.USER.PASS.DB;
		$this->connect(HOST,USER,PASS);
		$this->select_db(DB);
	}
	
	function connect($host,$user,$pass){
		if (!mysql_connect($host,$user,$pass))
			die('Could not connect: ' . mysql_error());
	}
	
	function select_db($db){
		if (!mysql_select_db($db)){
			die('Could not connect: ' . mysql_error());
		}
	}
	
	function query($query,$log = true){
		$result = mysql_query($query);		
		//Record Logs
		$command = explode(" ",$query);
		if($log && (eregi('INSERT',$command[0]) || eregi('DELETE',$command[0]) || eregi('UPDATE',$command[0]) || mysql_error())){
			if(mysql_insert_id()) $this->insert_id = mysql_insert_id();
			mysql_query("INSERT INTO `log`(`query`,`error`,`date`,`username`) VALUES (\"".mysql_real_escape_string($query)."\",\"".mysql_error()."\",\"".time()."\",\"".@$_SESSION['username']."\")");
		}
		#echo mysql_error();
		return $result;
	}
	
	function fetch($result=''){		
		return $result?mysql_fetch_array($result):mysql_fetch_array($this->result);
	}
	
	function num_rows($result=''){		
		return $result?mysql_num_rows($result):mysql_num_rows($this->result);
	}
	
	function escape(&$s){
		$s = mysql_real_escape_string($s);
	}
}
?>